package com.bharat.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;

import com.bharat.domain.Test;

public class TestDaoImpl implements ITestDao {

	private final Logger log = Logger.getLogger(TestDaoImpl.class); 
	
	private SessionFactory sessionFactory;

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	// constructor
	public TestDaoImpl() {
	}

	@Override
	public Test getTestById(int testId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int createTest(Test test) {
		log.info("create test dao: " + test);
		int status = 0;
		this.sessionFactory.getCurrentSession().save(test);
		return status;
	}

	@Override
	public int updateTest(Test test) {
		int status = 0;
		this.sessionFactory.getCurrentSession().update(test);
		return status;
	}

	@Override
	public List<Test> getAllTests() {
		List<Test> lst = new ArrayList<Test>();
		lst = this.sessionFactory.getCurrentSession().createCriteria(Test.class).list();
		return lst;
	}

	@Override
	public int deleteTest(Test test) {
		int status = 0; 
		this.sessionFactory.getCurrentSession().delete(test);
		return status;
	}

}
